package com.lxx.onlineview.controller;

import com.lxx.onlineview.entity.po.Teacher;
import com.lxx.onlineview.entity.po.User;
import com.lxx.onlineview.results.Result;
import com.lxx.onlineview.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    UserService userService;


    @RequestMapping("/login")
    public Result<String> login(@RequestParam("userName") String userName, @RequestParam("password") String password) {
        return userService.login(userName, password);
    }
    @RequestMapping("/update")
    public Result<User> update(User user){
        return userService.updateUser(user);
    }

    @RequestMapping("/getByType")
    public Result<List<User>> getUserByType(String type){
        return userService.getByType(type);
    }

    @RequestMapping("/getByUserName")
    public Result<User> getByUserName(String userName){
        return userService.getByUserName(userName);
    }


   /* @PostMapping("/register")
    public Result<String> register(@RequestParam("userName") String userName,
                                   @RequestParam("password") String password,
                                   @RequestParam("uid") int uid,
                                   @RequestParam("college") String college,
                                   @RequestParam("className") String className,
                                   @RequestParam("grade") String grade) {

        User user = userService.getByUserName(userName);

        if (null != user) {
            // 用户名已经存在，抛出异常
            return Result.error(CodeMsg.USERNAME_NOT_EXIST);
        }

        user = new User();
        user.setUserName(userName);
        // 注意存在数据库中的是提交的表单再加密的DBPass
        user.setPassword(MD5Util.formPassToDBPass(password));
        user.setClassName(className);
        user.setCollege(college);
        user.setUid(uid);
        user.setGrade(grade);

        userService.setUser(user);
        return Result.success("注册成功！");
    }*/
}
